<template>
    <div>
        <van-cell>
          <!-- 使用 title 插槽来自定义标题 -->
          <template #title>
            <div class="title-box">
                <span>{{artObj.title}}</span>
                <!-- 单图 -->
                <img v-if="artObj.cover.type === 1" class="thumb" v-lazy="artObj.cover.images[0]" alt="">
                <!-- <img v-if="artObj.cover.type === 1" class="thumb" :src="artObj.cover.images[0]" alt=""> -->
                <!-- <van-image v-if="artObj.cover.type === 1" class="thumb" :src="artObj.cover.images[0]">
                  <template v-slot:error>图片走丢了</template>
                </van-image> -->
            </div>
            <!-- 多图 -->
            <div class="thumb-box" v-if="artObj.cover.type > 1">
              <!-- <img class="thumb"
              :src="imgUrl"
              alt=""
              v-for="(imgUrl,index) in artObj.cover.images"
              :key="index"> -->
              <img class="thumb"
              v-lazy='imgUrl'
              alt=""
              v-for="(imgUrl,index) in artObj.cover.images"
              :key="index">
              <!-- <van-image
                class="thumb"
                :src="imgUrl"
                v-for="(imgUrl,index) in artObj.cover.images"
                :key="index">
                <template v-slot:error>图片走丢了</template>
              </van-image> -->
            </div>
          </template>
          <template #label>
            <div class="label-box">
                <div>
                    <span>{{artObj.art_name}}</span>
                    <span>{{artObj.comm_count}}评论</span>
                    <span>{{artObj.pubdate}}月前</span>
                </div>
                <van-icon name="cross"  @click.stop="show = true" v-if="isShow"/>
            </div>
          </template>
        </van-cell>
        <van-action-sheet
        v-model="show"
        :actions="actions"
        @select="onSelect"
        @cancel="onCancel"
        @close="onClose"
        :cancel-text="bottomText"
        get-container="body"/>
    </div>
</template>

<script>
// 目标1：点击"反馈垃圾内容"数据切换
// 1、监听点击事件，区分用户点击的是哪一个
// 2、切换action数组里的数据

// 目标2:二级反馈数据出现，取消按钮换成"返回"
// :cancel-text设置变量，点击onSelect把变量换成"返回"

// 目标3：点击底部按钮，要区分判断
// 1、标签@cancel取消事件和事件方法
// 2、再里面用bottomText的值，判断用户点击的是否为"返回"
// 把actions数据源换回成firstAction
import { firstAction, secondAction } from '../api/report'
export default {
  data () {
    return {
      show: false, // 反馈面板显示/隐藏
      actions: firstAction,
      bottomText: '取消'
    }
  },
  props: {
    artObj: Object,
    isShow: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    // action 点击的内容, item索引值
    onSelect (action, item) {
      console.log(action, item)
      // 默认情况下点击选项时不会自动收起
      // 可以通过 close-on-click-action 属性开启自动收起
      if (action.name === '反馈垃圾内容') {
        this.actions = secondAction
        this.bottomText = '返回'
      } else if (action.name === '不感兴趣') {
        this.$emit('disLikeEV', this.artObj.art_id)
        this.show = false // 不管成功或者失败。直接让反馈面板消失
      } else {
        this.$emit('reportEV', this.artObj.art_id, action.value)
        this.show = false
      }
      // this.show = false
    },
    // 底部按钮点击事件
    onCancel () {
      if (this.bottomText === '返回') {
        this.show = true
        this.actions = firstAction
        this.bottomText = '取消'
      }
    },
    // 关闭面板-触发事件
    onClose () {
      // this.show = true
      this.actions = firstAction
      this.bottomText = '取消'
    }
    // // 文章详情
    // detailFn () {
    //   console.log('111')
    // }
  }
}
</script>

<style lang='less' scoped>
.title-box{
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.label-box{
  display: flex;
  justify-content: space-between;
  align-items: flex-start;

  span{
    margin: 0 3px;

    &:first-child{
      margin-left: 0;
    }
  }
}

//图片样式
.thumb{
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
.thumb-box{
  display: flex;
  justify-content: space-between;
}
</style>
